//
//  LuanchPage.swift
//  GoCash
//
//  Created by jie on 2024/5/13.
//

import SwiftUI

struct LuanchPage: View {
    
    @EnvironmentObject var appState: AppState
        
    var body: some View {
        ZStack {
            Image("luanch_bg", bundle: nil).resizable().ignoresSafeArea()
            GeometryReader(content: { geometry in
                VStack(alignment: .leading, spacing: 0) {
                    Spacer()
                    Text("Bienvenidos a").font(Font.system(size: 32, weight: .bold)).fontWeight(.bold).foregroundColor(Color(hex:0x312A31)).padding(.bottom, 0)
                    Text(APP_NAME).font(Font.system(size: 32, weight: .bold)).fontWeight(.bold).foregroundColor(Color(hex:0x8E55D7)).padding(.top, 0)
                    Text("Excelente servicio, revisión automática y rápida").foregroundColor(Color(hex: 0x7C697C)).font(Font.system(size: 18, weight: .medium)).padding(.top, 20)
                }.padding(EdgeInsets(top: 0, leading: 24, bottom: geometry.safeAreaInsets.bottom+80, trailing: 24))
            })
        }
        .onAppear() {
            DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
                appState.alertView = AnyView(LuanchStatement())
                appState.showAlert = true
            }
        }
    }
}

#Preview {
    LuanchStatement()
}



struct LuanchStatement: View {
    
    @State var alpha: Double = 0.2
    @State var factor: Double = 0.5
    
    var body: some View {
        ZStack {
            VStack(alignment: .center, spacing: 0) {
                Text("Declaración de autor").font(Font.system(size: 18, weight: .semibold)).foregroundColor(COLOR_312A31)
                
                HStack {
                    Text("在您开始使用我们的服务之前，请阅读并接受").font(Font.system(size: 14, weight: .regular)).foregroundColor(COLOR_312A31).padding(.top, 16)
                    Spacer()
                }
                
                LuanchStatementTextItem(title: .constant("相机"), desc: .constant("用于摄像头接入上传照片ID设备识别信息。"))
                LuanchStatementTextItem(title: .constant("位置"), desc: .constant("用于确认居住信息。 经客户同意后，数据被发送至服务器并用于反欺诈服务。"))
                LuanchStatementTextItem(title: .constant("存储"), desc: .constant("允许您上传贷款申请的文件和图像。我们致力于不断改进我们的安全技术和系统，以确保您的个人信息安全。"))
                LuanchStatementTextItem(title: .constant("设备信息"), desc: .constant("我们收集有关您设备的特定信息，包括其硬件型号、操作系统和版本、唯一设备标"))
                
                HStack(spacing: 12) {
                    Button(action: {
                        exit(1)
                    }, label: {
                        ZStack {
                            RoundedRectangle(cornerRadius: 15)
                                .foregroundColor(.white)
                                .overlay {
                                    RoundedRectangle(cornerRadius: 16, style: .continuous)
                                        .stroke(MAIN_COLOR, lineWidth: 2)
                                }
                            Text("Rechazar").foregroundColor(MAIN_COLOR).font(Font.system(size: 18, weight: .bold))
                        }
                    }).frame(height: 50)
                    
                    Button(action: {
                        withAnimation(.linear(duration: 0.3)) {
                            alpha = 0
                            factor = 0
                        }
                        AppState.shared.mainPageState = 2
                        AppState.shared.showAlert = false
                    }, label: {
                        ZStack {
                            RoundedRectangle(cornerRadius: 15)
                                .foregroundColor(MAIN_COLOR)
                            Text("Confirmar").foregroundColor(.white).font(Font.system(size: 18, weight: .bold))
                        }
                    }).frame(height: 50)
                }.frame(height: 50)
                .padding(.bottom, 4)
                .padding(.top, 20)
                
            }.padding(16)
            .background(.white)
            .cornerRadius(15)
        }
        .opacity(alpha)
        .scaleEffect(factor)
        .padding(.leading, 32).padding(.trailing, 32)
        .onAppear(){
            withAnimation(.linear(duration: 0.35)) {
                alpha = 1
                factor = 1
            }
        }
    }
}


struct LuanchStatementTextItem: View {
    
    @Binding var title: String
    @Binding var desc: String
    
    var body: some View {
        HStack {
            Text(title).font(Font.system(size: 14, weight: .medium)).foregroundColor(COLOR_312A31).padding(.top, 16)
            Spacer()
        }
        
        HStack {
            Text(desc).font(Font.system(size: 14, weight: .regular)).foregroundColor(COLOR_312A31).padding(.top, 16)
            Spacer()
        }.padding(EdgeInsets(top: -12, leading: 0, bottom: 0, trailing: 0))
    }
}



